import Koa from 'koa'
// import { router } from './router/blogs.js'
import Router from 'koa-router'
import nunjucks from 'nunjucks'
import {fileURLToPath}from 'url'
const app=new Koa()
const router=new Router()
// app.use(render())

router.get('/blogs',async (ctx,next)=>{
    let path=new URL('./views',import.meta.url)
    let newpath=fileURLToPath(path.href)
    console.log(newpath);
    
    let env=nunjucks.configure(newpath,{noCache:true})
    ctx.body=env.render('blogs.html',{blogs:[
        {
            ID:1,
            Title:"快乐"
        }
    ]})
})
app.use(router.routes())
app.listen(5000,()=>{
    console.log('服务器运行于如下地址：http://localhost:5000');
    
})